// 问题：构造杨辉三角
import R from 'ramda';

const recursiveOf = (maxDepth: number) =>
    <T>(f: ((v: T) => T), v: T): T[] => {
        let res: T[] = [v];

        let recurse: T = f(v);
        for (let i = 0; i < 10; i++) {
            res = [...res, recurse];
            recurse = f(recurse);
        }

        return res;
    }

// 函数式
const nextLine = (prevLine: number[]) => [1, ...R.aperture(2, prevLine).map(([a, b]) => a + b), 1];
const triangleList = recursiveOf(10)(nextLine, [1]);
const formatTriangle = (n: number) => R.take(n)(triangleList).map(R.join(' ')).map((v, i) => ' '.repeat(n - i) + v).join('\n')
console.log(formatTriangle(7));